local zhilei = fk.CreateSkill {
  name = "emo__zhilei",
}

Fk:loadTranslationTable{
  ["emo__zhilei"] = "制雷",
  [":emo__zhilei"] = "出牌阶段对每名角色限一次，你可以选一项：1.将一张黑色牌当【定时炸弹】对其使用；2.弃置一张黑色牌，引爆其判定区内的【定时炸弹】。",

  ["#emo__zhilei-prompt"] = "制雷：每角色限一次，你可将一张黑色牌当【定时炸弹】使用，若其已有炸弹，引爆之！",
}

zhilei:addEffect("active", {
  anim_type = "offensive",
  card_num = 1,
  target_num = 1,
  prompt = "#emo__zhilei-prompt",
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  target_filter = function (self, player, target, selected, selected_cards)
    if #selected == 0 and #selected_cards > 0 and target:getMark("emo__zhilei_target-phase") == 0 then
      if target:hasDelayedTrick("timebomb") then
        return not player:prohibitDiscard(selected_cards[1])
      else
        local card = Fk:cloneCard("timebomb")
        card:addSubcard(selected_cards[1])
        return player:canUseTo(card, target)
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:addPlayerMark(target, "emo__zhilei_target-phase", 1)
    if target:hasDelayedTrick("timebomb") then -- 引爆
      room:throwCard(effect.cards, zhilei.name, player, player)
      for _, id in ipairs(target:getCardIds("j")) do
        local card = target:getVirtualEquip(id) or Fk:getCardById(id)
        if card.name == "timebomb" then
          room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, zhilei.name)
          room:damage {
            from = nil, to = target, damage = 2, card = card, skillName = "timebomb_skill",
            damageType = (math.random(1, 2) == 1 and fk.FireDamage or fk.ThunderDamage)
          }
        end
      end
    else
      room:useVirtualCard("timebomb", effect.cards, player, target, zhilei.name)
    end
  end,
})

return zhilei
